class Requisicao < ActiveRecord::Base
  belongs_to :hospedagem
  belongs_to :servico
  attr_accessible :estornado, :preco_unitario, :qtd, :hospedagem_id, :servico_id

  validates_presence_of :hospedagem_id, :servico_id, :qtd
  validates_inclusion_of :estornado, :in => [true, false]
  validates_numericality_of :qtd

  before_save :set_preco_unitario

  private
  def set_preco_unitario
  	self.preco_unitario = servico.preco
  end
end
